<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li{
            background-color: pink;
            margin-bottom: 2px;
            width: 400px;
        }
    </style>
</head><script src="../../day6jquery/jquery3.5.min.js"></script> 
<body>
    <textarea name=""></textarea>
    <button>发布</button>
    <ul></ul>

    <script>
        let btn = document.querySelector('button');
        let text = document.querySelector('textarea')
        let ul = document.querySelector('ul');
        btn.onclick = function(){
           if(text.value == ''){
               alert('请输入内容')
           }else{
            let li = document.createElement('li');
            li.innerHTML = text.value;
            text.value = ''
            // ul.appendChild(li);放到最后面
            ul.insertBefore(li,ul.children[0])//放到最前面
           }
            
        }
    </script>
</body>
</html>